//
//  DRButton.m
//  F2FClient
//
//  Created by xujingjing on 15/10/13.
//  Copyright © 2015年 xujingjing. All rights reserved.
//

#import "DRButton.h"
#import "NSString+KKSizeString.h"

@interface DRButton () {
    CGSize titleSize;
}

@end

@implementation DRButton

#pragma mark interface
- (void)willMoveToSuperview:(UIView *)newSuperview {
    [super willMoveToSuperview:newSuperview];
    titleSize = [self.titleLabel.text  getSizeWithFont:self.titleLabel.font width:self.frame.size.width height:self.frame.size.height];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}
#pragma mark super methods
//set background image position and bounds
- (CGRect)backgroundRectForBounds:(CGRect)bounds {
    CGRect retValue = CGRectMake((self.frame.size.width-(self.frame.size.height-titleSize.height))/2, 0, self.frame.size.height-titleSize.height, self.frame.size.height-titleSize.height);
    return retValue;
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect{

    CGRect retValue = CGRectMake((self.frame.size.width-(self.frame.size.height-titleSize.height))/2, 0, self.frame.size.height-titleSize.height, self.frame.size.height-titleSize.height);
    return retValue;

}
//set title position
- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    CGRect retValue = CGRectMake(0, self.frame.size.height-titleSize.height, contentRect.size.width, titleSize.height);
    return retValue;
}
/*
 
 
 //图片是60*60的2x的图
 CGFloat imageWith = 30;
 CGFloat imageHeight = 30;
 
 CGFloat labelWidth = [self.originalButton.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.originalButton.titleLabel.font}].width;
 CGFloat labelHeight = [self.originalButton.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.originalButton.titleLabel.font}].height;
 
 
 //image在后，文字在前
 self.oneButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
 self.oneButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWith, 0, imageWith);
 
 self.oneButton_line.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
 self.oneButton_line.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWith, 0, imageWith);
 
 //image在上，文字在下
 CGFloat imageOffsetX = (imageWith + labelWidth) / 2 - imageWith / 2;//image中心移动的x距离
 CGFloat imageOffsetY = imageHeight / 2;//image中心移动的y距离
 CGFloat labelOffsetX = (imageWith + labelWidth / 2) - (imageWith + labelWidth) / 2;//label中心移动的x距离
 CGFloat labelOffsetY = labelHeight / 2;//label中心移动的y距离
 
 self.twoButton.imageEdgeInsets = UIEdgeInsetsMake(-imageOffsetY, imageOffsetX, imageOffsetY, -imageOffsetX);
 self.twoButton.titleEdgeInsets = UIEdgeInsetsMake(labelOffsetY, -labelOffsetX, -labelOffsetY, labelOffsetX);
 
 self.twoButton_line.imageEdgeInsets = UIEdgeInsetsMake(-imageOffsetY, imageOffsetX, imageOffsetY, -imageOffsetX);
 self.twoButton_line.titleEdgeInsets = UIEdgeInsetsMake(labelOffsetY, -labelOffsetX, -labelOffsetY, labelOffsetX);
 
 
 //image，label中间间隔10
 self.threeButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
 self.threeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
 
 self.threeButton_line.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
 self.threeButton_line.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
 
 
 
 
 
 
 */
@end










